package com.moyq5.mvc.maker.test.bean.entity;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.moyq5.mvc.maker.test.bean.enums.MerchBizType;
import com.moyq5.mvc.maker.test.bean.enums.SysEngageType;
import com.moyq5.mvc.maker.test.bean.enums.SysFeeHandle;
import com.moyq5.mvc.maker.test.bean.enums.SysLiquidateType;
import com.moyq5.mvc.maker.test.bean.enums.SysSettleType;

/**
 * 商家信息
 * @author Moyq5
 * @date 2018年4月13日
 */
@Entity
@Table(name = "uc_merch")
@DynamicUpdate
public class Merch implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 商家ID
	 */
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "merch_id")
	private Long merchId;
	/**
	 * 商户编号
	 */
	@Column(name = "merch_no", length = 20, nullable = false)
	private String merchNo;
	/**
	 * 代理商
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "agent_id", nullable = false)
	private Agent agent;
	/**
	 * 银行账户
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "bank_account_id", nullable = false)
	private BankAccount bankAccount;
	/**
	 * 虚拟账户
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "virtual_account_id", nullable = false)
	private VirtualAccount virtualAccount;
	/**
	 * 微信公众号
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "weixin_id")
	private Weixin weixin;
	/**
	 * 商家名称
	 */
    @Column(name = "name", length = 100, nullable = false)
	private String name;
    /**
	 * 商户全称
	 */
	@Column(name = "full_name", length = 100, nullable = false)
	private String fullName;
	/**
	 * 商户LOGO
	 */
	@Column(name = "logo", length = 200)
	private String logo;
	/**
	 * 手机号
	 */
    @Column(name = "mobile", length = 20)
	private String mobile;
    /**
	 * 联系人
	 */
    @Column(name = "contacts", length = 20)
	private String contacts;
    /**
	 * 联系电话
	 */
    @Column(name = "tel", length = 20)
	private String tel;
    /**
	 * 联系邮箱
	 */
    @Column(name = "email", length = 60)
	private String email;
    /**
	 * 地址
	 */
    @Column(name = "address", length = 200)
	private String address;
	/**
     * 经营模式
     */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "engage_type", precision = 2, nullable = false)
	private SysEngageType engageType;
    /**
     * 结算类型
     */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "settle_type", precision = 2)
	private SysSettleType settleType;
    /**
     * 结算延时时间（单位：分钟）
     */
    @Column(name = "settle_lazy", precision = 8, scale = 0, nullable = false)
	private Integer settleLazy;
    /**
     * 结算方
     */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "liquidate_type", precision = 2)
	private SysLiquidateType liquidateType;
    /**
     * 手续费扣除方式<br>
     * 注意，变更时，请确认虚拟账户不能有余额
     */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "fee_handle", precision = 2)
	private SysFeeHandle feeHandle;
    /**
     * 开通业务类型，多选
     * @see {@link MerchBizType}
     */
    @Column(name = "biz_type", precision = 8, scale = 0, columnDefinition="int(8) default '0'")
    private Integer  bizType;
    
    /**
     * 业务扩展信息，即达到支持某些业务需要的商户其它信息
     */
    @OneToOne(mappedBy="merch", optional = true)
    private MerchBizExt bizExt;
    /**
	 * 支付交易限制
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pay_confine_id")
	private TraConfine payConfine;
	
	/**
	 * 提现交易限制
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "remit_confine_id")
	private TraConfine remitConfine;
	/**
	 * 提现单笔费率，如：0.0049
	 */
	@Column(name = "remit_rate", columnDefinition = "decimal(5,4) not null default '0.0000'")
	private BigDecimal remitRate;
	/**
	 * 提现单笔提现费（元）
	 */
	@Column(name = "remit_fee", columnDefinition = "decimal(10,2) not null default '2.00'")
	private BigDecimal remitFee;
	/**
	 * 提现自动出款时间，（24小时）多选，注意，此参数由上级代理管制
	 */
	@Column(name = "remit_hours", precision = 8, scale = 0, columnDefinition = "int(8) not null default '16777215'")
	private Integer remitHours;
	/**
	 * 添加（注册）时间
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;
	
	@PrePersist
	public void prePersist() {
		if (null == remitHours) {
			remitHours = 16777215;
		}
		if (null == addTime) {
			addTime = new Date();
		}
		if (null == merchNo) {
			merchNo = String.valueOf(System.currentTimeMillis()+Long.MAX_VALUE) + Math.round(Math.random() * (1e6-1e5-1) + 1e5);
			merchNo = merchNo.substring(merchNo.length() - 18, merchNo.length());
		}
	}

	public Long getMerchId() {
		return merchId;
	}

	public void setMerchId(Long merchId) {
		this.merchId = merchId;
	}

	public String getMerchNo() {
		return merchNo;
	}

	public void setMerchNo(String merchNo) {
		this.merchNo = merchNo;
	}

	public Agent getAgent() {
		return agent;
	}

	public void setAgent(Agent agent) {
		this.agent = agent;
	}

	public BankAccount getBankAccount() {
		return bankAccount;
	}

	public void setBankAccount(BankAccount bankAccount) {
		this.bankAccount = bankAccount;
	}

	public VirtualAccount getVirtualAccount() {
		return virtualAccount;
	}

	public void setVirtualAccount(VirtualAccount virtualAccount) {
		this.virtualAccount = virtualAccount;
	}

	public Weixin getWeixin() {
		return weixin;
	}

	public void setWeixin(Weixin weixin) {
		this.weixin = weixin;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public String getLogo() {
		return logo;
	}

	public void setLogo(String logo) {
		this.logo = logo;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getContacts() {
		return contacts;
	}

	public void setContacts(String contacts) {
		this.contacts = contacts;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public SysSettleType getSettleType() {
		return settleType;
	}

	public void setSettleType(SysSettleType settleType) {
		this.settleType = settleType;
	}

	public SysLiquidateType getLiquidateType() {
		return liquidateType;
	}

	public void setLiquidateType(SysLiquidateType liquidateType) {
		this.liquidateType = liquidateType;
	}

	public SysFeeHandle getFeeHandle() {
		return feeHandle;
	}

	public void setFeeHandle(SysFeeHandle feeHandle) {
		this.feeHandle = feeHandle;
	}

	public Integer getBizType() {
		return bizType;
	}

	public void setBizType(Integer bizType) {
		this.bizType = bizType;
	}

	public MerchBizExt getBizExt() {
		return bizExt;
	}

	public void setBizExt(MerchBizExt bizExt) {
		this.bizExt = bizExt;
	}

	public Date getAddTime() {
		return addTime;
	}

	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}

	public TraConfine getPayConfine() {
		return payConfine;
	}

	public void setPayConfine(TraConfine payConfine) {
		this.payConfine = payConfine;
	}

	public TraConfine getRemitConfine() {
		return remitConfine;
	}

	public void setRemitConfine(TraConfine remitConfine) {
		this.remitConfine = remitConfine;
	}

	public SysEngageType getEngageType() {
		return engageType;
	}

	public void setEngageType(SysEngageType engageType) {
		this.engageType = engageType;
	}

	public BigDecimal getRemitRate() {
		return remitRate;
	}

	public void setRemitRate(BigDecimal remitRate) {
		this.remitRate = remitRate;
	}

	public BigDecimal getRemitFee() {
		return remitFee;
	}

	public void setRemitFee(BigDecimal remitFee) {
		this.remitFee = remitFee;
	}

	public Integer getSettleLazy() {
		return settleLazy;
	}

	public void setSettleLazy(Integer settleLazy) {
		this.settleLazy = settleLazy;
	}

	public Integer getRemitHours() {
		return remitHours;
	}

	public void setRemitHours(Integer remitHours) {
		this.remitHours = remitHours;
	}
	
}
